package com.gdth.bank.activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.gdth.bank.R;
import com.gdth.bank.adapter.DividerItemDecoration;
import com.gdth.bank.adapter.UnbindAppAdapter;
import com.gdth.bank.bean.AppDevBean;
import com.gdth.bank.presenter.UnbindAppPresenter;
import com.gdth.bank.view.UnbindAppView;
import com.gdth.core.annotation.view.ViewInject;
import com.gdth.core.widget.BaseActivity;
import com.gdth.widget.dialog.BaseToast;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xjc
 * 创建时间： 2020/5/11 4:46 PM
 * @version V1.0
 * 用途:
 */
public class UnbindYHActivity extends BaseActivity implements UnbindAppView  {
    @ViewInject(id = R.id.header_label_title)
    TextView txt_header_title;
    @ViewInject(id = R.id.header_btn_left, click = "finishClick")
    TextView txt_header_left;
    @ViewInject(id = R.id.header_btn_right)
    TextView txt_header_right;
    private UnbindAppPresenter unbindAppPresenter;
    private UnbindAppAdapter mAdapter;
    private List<AppDevBean.YhListBean> applist = new ArrayList<>();
    private ListView mlistView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_unbind_yh);
        mlistView = findViewById(R.id.unbind_list);
        unbindAppPresenter = new UnbindAppPresenter(this);
        txt_header_title.setText("解绑APP");
        txt_header_right.setVisibility(View.GONE);
        initAdapter();
        initData();
    }
    private AlertDialog.Builder builder;
    private void showDialog(String content) {

        builder = new AlertDialog.Builder(this).setTitle("温馨提示")
                .setMessage("是否删除该条记录")
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
                        dialogInterface.dismiss();
                    }
                }).setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        unbindAppPresenter.delAppDev(content);
                        dialog.dismiss();
                    }
                });
        builder.create().show();
    }

    private void initAdapter() {
        mAdapter = new UnbindAppAdapter(UnbindYHActivity.this,applist);
        //开启动画效果
        mlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showDialog(applist.get(position).getSFZ());
            }
        });
        mlistView.setAdapter(mAdapter);
    }



    public void initData(){
        unbindAppPresenter.getAppdevList();
    }

    @Override
    public void updateView(String content) {
        initData();
    }

    @Override
    public void saveSuccess(List<AppDevBean.YhListBean> bean) {
        this.runOnUiThread(new Runnable() {
            public void run() {
                applist.clear();
                applist.addAll(bean);
                mAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void showProgressDialog(String msg) {

    }

    @Override
    public void hideProgressDialog() {

    }

    @Override
    public void showMessage(String msg) {

    }


}
